package net.butfly.bus.filter;

import java.util.Map;

import net.butfly.bus.Request;
import net.butfly.bus.Response;

public abstract class FilterBase {

	private Map<String, String> initParamMap;

	public FilterBase() {}

	public void init() throws Throwable {}

	public abstract void execute(Request request, Response response) throws Exception;

	public void destroy() {}

	public void setInitParamMap(Map<String, String> initParams) {
		this.initParamMap = initParams;
	}

	public String getInitParamAsString(String paramName) {
		return initParamMap != null ? initParamMap.get(paramName) : null;
	}

	public int getInitParamAsInt(String paramName) {
		String ts = getInitParamAsString(paramName);
		return ts != null ? Integer.parseInt(ts) : 0;
	}

	public boolean getInitParamAsBoolean(String paramName) {
		String ts = getInitParamAsString(paramName);
		return ts != null ? Boolean.parseBoolean(ts) : false;
	}
}